# -*- coding: utf-8 -*-

from odoo.http import request

from odoo_contrib import http as contrib_http
from odoo_contrib.parser import parse_with
from odoo_contrib.marshal import marshal_with

from ..schemas import parser
from ..schemas import marshals


@contrib_http.route('/exhibition')
class CarouselRepository(contrib_http.Controller):
    @contrib_http.route('/carousel/', methods=['GET'])
    @parse_with(parser.carousel.CarouselRepositorySchema)
    @marshal_with(marshals.carousel.CarouselRepositorySchema, envelope='data')
    def carousel_list(self):
        params = self.parser.parse()
        limit = params['limit']
        enabled_only = params['enabled_only']

        domains = []
        if enabled_only:
            domains.append(('enabled', '=', True))

        carousels = request.env['exhibition.carousel'].search(
            domains,
            limit=limit,
        )
        return {
            'entries': carousels,
            'count': request.env['exhibition.carousel'].search_count(domains),
        }
